package schoolDemo3;

class Cylinder{
    private double radius;
    private int height;
    private double pi=3.14;
    private String color;
    public static String sayHello="你好";
    public void setCylinder(double r,int h){
        if(r>0&&h>0){
            radius=r;
            height=h;
        }
        else
            System.out.println("输入数据有误！");
    }
    double area(){
        return pi*radius*radius;
    }
    double volume(){
        return area()*height;
    }
//通过无参数的构造方法调用下面有参数的构造方法
    public Cylinder(){
        this(9.2,10,"红色");
    };
    //重载构造函数
    public Cylinder(double r,int h,String str){
        radius=r;
        height=h;
        color=str;
        System.out.println("现有一个半径为："+radius+"高为："+height+"颜色为"+color+"的圆柱体：");
    }
}
public class App7_2 {
    public static void main(String[] args) {
        Cylinder volu=new Cylinder();
        volu.setCylinder(13.5,20);
        System.out.println("圆柱的底面积是："+volu.area());
        System.out.println("圆柱的体积是："+volu.volume());
        Cylinder volu2=new Cylinder(10.5,20,"蓝色");
        System.out.println("圆柱的底面积是："+volu2.area());
        System.out.println("圆柱的体积是："+volu2.volume());
        System.out.println();
    }
}
